﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SqlDataAccess;

namespace QuanLyBanHang
{
	public partial class F221_Danh_sach_hoa_don_ban : Form
	{
		public F221_Danh_sach_hoa_don_ban()
		{
			InitializeComponent();
            set_define_events();
		}

		#region Members
        
		BKIQuanLyBanHangEntities db = new BKIQuanLyBanHangEntities();
		#endregion

		#region Private Methods
		private void set_define_events()
		{
			this.Load += F221_Danh_sach_hoa_don_ban_Load;
			this.m_cmd_chon.Click += m_cmd_chon_Click;
			this.m_cmd_tim_kiem.Click += m_cmd_tim_kiem_Click;
		}

		private void load_data_to_grid()
		{
			var v_lst_hoa_don_ban = db.GD_HOA_DON_BAN
				.Where(x=>x.MA_HOA_DON_BAN.Contains(m_txt_tu_khoa.Text)
					|| x.HT_NGUOI_SU_DUNG.HO_TEN_NHAN_VIEN.Contains(m_txt_tu_khoa.Text)
					||m_txt_tu_khoa.Text.Equals(""))
				.Select(x => new
				{
					ID=x.ID,
					MA_HOA_DON_BAN=x.MA_HOA_DON_BAN,
					NGAY_BAN = x.NGAY_BAN,
					TEN_NHAN_VIEN=x.HT_NGUOI_SU_DUNG.HO_TEN_NHAN_VIEN,
					MO_TA=x.MO_TA,
					THANH_TIEN=x.THANH_TIEN,
					DA_THANH_TOAN=x.DA_THANH_TOAN,
					KHACH_HANG_NO = x.KHACH_HANG_NO
				})
				.ToList();
			m_grv.DataSource = v_lst_hoa_don_ban;
			//col ID
			m_grv.Columns[0].Width = 20;
			m_grv.Columns[0].Visible = true;

			m_grv.Columns[1].HeaderText = "Mã hoá đơn";
			m_grv.Columns[2].HeaderText = "Ngày bán";
			m_grv.Columns[3].HeaderText = "Nhân viên";
			m_grv.Columns[4].HeaderText = "Mô tả";
			m_grv.Columns[5].HeaderText = "Thành tiền";
			m_grv.Columns[6].HeaderText = "Đã thanh toán";
			m_grv.Columns[7].HeaderText = "Khách hàng nợ";
		}
		#endregion

		#region Events
		void m_cmd_tim_kiem_Click(object sender, EventArgs e)
		{
			try
			{
				load_data_to_grid();
			}
			catch (Exception v_e)
			{
				MessageBox.Show(v_e.ToString());
			}
		}

		void m_cmd_chon_Click(object sender, EventArgs e)
		{
			try
			{

			}
			catch (Exception v_e)
			{
				MessageBox.Show(v_e.ToString());
			}
		}

		void F221_Danh_sach_hoa_don_ban_Load(object sender, EventArgs e)
		{
			try
			{
				load_data_to_grid();
			}
			catch (Exception v_e)
			{
				MessageBox.Show(v_e.ToString());
			}
		}
        
		#endregion
	}
}
